package com.neustudy.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.neustudy.base.exception.NeuStudyExecption;
import com.neustudy.base.model.PageResult;
import com.neustudy.content.mapper.CourseTeacherMapper;
import com.neustudy.content.model.po.CourseTeacher;
import com.neustudy.content.service.CourseTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author WKX
 * @version 1.0
 * @describe todo
 * @create: 2024-11-11 17:06
 */
@Service
public class CourseTeacherServiceImpl implements CourseTeacherService {

    @Autowired
    CourseTeacherMapper courseTeacherMapper;

    @Override
    public List<CourseTeacher> queryCourseTeacherList(Long courseId) {
        LambdaQueryWrapper<CourseTeacher> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CourseTeacher::getCourseId , courseId);
        return courseTeacherMapper.selectList(wrapper);
    }

    @Override
    public CourseTeacher createCourseTeacher(CourseTeacher courseTeacher) {
        courseTeacher.setCreateDate(LocalDateTime.now());
        int i = courseTeacherMapper.insert(courseTeacher);
        if(i < 0){
            throw new NeuStudyExecption("添加老师信息失败");
        }
        return courseTeacher;
    }

    @Override
    public CourseTeacher updateCourseTeacher(CourseTeacher courseTeacher) {
        int i = courseTeacherMapper.updateById(courseTeacher);
        if(i<0){
            throw new NeuStudyExecption("修改老师信息失败");
        }
        return courseTeacher;
    }

    @Override
    public void deletCourseTeacher(Long courseId, Long teacherId) {
        LambdaQueryWrapper<CourseTeacher> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CourseTeacher::getCourseId,courseId);
        wrapper.eq(CourseTeacher::getId,teacherId);
        int i = courseTeacherMapper.delete(wrapper);
        if(i < 0){
            throw new NeuStudyExecption("删除老师信息失败");
        }
    }


}
